< previous page page_216 next page >

Page 216
note.gif You can't add some types of statements while your program is running. In these cases, Visual Basic informs you that you must stop and restart the application.  square.gif

Stepping through Your Code
Once you are in break mode, you have more options besides restarting execution. You can step through code line by line or skip statements entirely. Visual Basic has three methods of stepping through code, each of which can be performed from the Debug toolbar:
Step Over, which steps through lines in the current procedure but not through lines in any called procedures (the shortcut key is Shift+F8).
Step Into, which steps through lines in the current procedure and into any called procedures (Shortcut key: F8)
Step Out, which runs until the end of the current procedure (the shortcut key is Ctrl+Shift+F8).
To demonstrate stepping through code, end the sample project, and then press F8 several times. Notice that the program executes a line every time you press the function key. It also highlights the next statement in the Code window, as shown in Figure 10.1.
0216-01.jpg
Figure 10.1
When you are debugging, Visual
Basic allows you to set the next statement
by dragging the arrow in the margin.
If you want to skip statements or execute them again, you can use the Set Next Statement feature. Simply put the cursor on the statement you want, and then press Ctrl+F9 or choose Debug, Set Next Statement. You can also drag the arrow in the left margin so that it points to the next statement you want to execute.
Try it now: Step through the sample program until the arrow is pointing to the line of code that increments the variable i. Next, drag the arrow back to the previous Print statement, and step through it again by pressing F8. Notice that you have caused the same value of i to be printed twice.
In the code example, you have been stepping through a While loop. Suppose that you don't care about debugging the While loop, but what happens before and after it. Stepping through the While loop would be a real pain if you did not have to, especially if it was to execute 1,000 times. In this case, you would need to use breakpoints.

 
< previous page page_216 next page >